<% content_for :title do %>Verkoopcijfers<% end %>
<%form_tag(admin_sales_figures_path, :method => :get) do %>
<table>
	<tr>
		<td>Zoek op categorie:</td>
	</tr>
	<tr>
		<td><%= text_field_tag :category, @category%></td>
	</tr>
	<tr>
		<td>Verkocht vanaf:</td>
		<td>Verkocht tot:</td>
	</tr>
	<tr>
		<td><%=select_date @date_from, :prefix => :from, :start_year => 2000, :end_year => Time.now.year, :include_blank => true%></td>
		<td><%=select_date @date_to, :prefix => :to, :start_year => 2000, :end_year => Time.now.year, :include_blank => true%></td>
		<td><%=submit_tag 'Zoek'%></td>
	</tr>
</table>
<%end%>
<table>
	<%if(@total_stats != nil)%>
		<%if(@search_value != nil && @search_value != "")%>
		<tr>
			<td>Categorie:</td>
			<td><%=@search_value%></td>
		</tr>
		<%end%>
	<tr>
		<td>Totaal verkocht:</td>
		<td><%=@total_stats[:quantity]%></td>
	</tr>
	<tr>
		<td>Totale omzet:</td>
		<td><%=format_price(@total_stats[:price])%></td>
	</tr>
	<%end%>
</table>
<table>
	<%if(@products.size>0)%>
		<tr>
			<%sort = @params[:sort]%>
			<%sort_on = @params[:sort_on]%>
			<th align="left">Product <%= link_to image_tag("asc.gif"), admin_sales_figures_path(@params, @params[:sort] = 'ASC', @params[:sort_on] = 'products.name')%><%= link_to image_tag("desc.gif"), admin_sales_figures_path(@params, @params[:sort] = 'DESC', @params[:sort_on] = 'products.name')%></td>
			<th align="left">Aantal verkocht <%= link_to image_tag("asc.gif"), admin_sales_figures_path(@params, @params[:sort] = 'ASC', @params[:sort_on] = 'total_quantity')%><%= link_to image_tag("desc.gif"), admin_sales_figures_path(@params, @params[:sort] = 'DESC', @params[:sort_on] = 'total_quantity')%></td>
			<th align="left">Omzet: <%= link_to image_tag("asc.gif"), admin_sales_figures_path(@params, @params[:sort] = 'ASC', @params[:sort_on] = 'total_price')%><%= link_to image_tag("desc.gif"), admin_sales_figures_path(@params, @params[:sort] = 'DESC', @params[:sort_on] = 'total_price')%></td>
			<%@params[:sort] = sort%>
			<%@params[:sort_on] = sort_on%>
		</tr>	
	<%end%>
	<% @products.each do |item|%>
		<%if(item.id != nil)%>
			<tr>
				<td><%=item.name%></td>
				<td><%=item.total_quantity%></td>
				<td><%=format_price(item.total_price)%></td>
			</tr>
		<%end%>
	<%end%>
</table>
<p>
<% if @indices[0] > -1 then%>
	<%= link_to 'vorige', admin_sales_figures_path(@params, @params[:page] = @indices[0])%>
<%end%>
<% if @indices[1] != nil then%>
	<%= link_to 'volgende', admin_sales_figures_path(@params, @params[:page] = @indices[1])%>
<%end%>
</p>